<?php
$auth = Auth::getAuth('current_user');
$db = new Database;
$fs = new functions;
$userCompany = new userQueries();
$company = $userCompany->getCompany($auth['company_id']);
if(isset($_POST) and $_SERVER['REQUEST_METHOD']=="POST"){
	// User file path
	$path = "images/formImage";
	$profilePic = $_FILES['image']['name'];
	$profilePic_size = $_FILES['image']['size']; // File Size
	
            $ext = explode(".", $profilePic);
            $last_ext = $ext[count($ext)-1];
	    
        // Allowed extension for file upload in the registration    
        $valid_formats = array("jpg", "png", "JPG", "PNG", "GIF", "gif");
        
            if(!in_array($last_ext,$valid_formats)){
                echo "Invalid File Format";
            }else{
                    if ($profilePic_size=="0"){
                        echo "File too large. File must be less than 4 megabytes.";
                    }else{
                        $thumbnail = $path . "/" . md5($profilePic . time() . md5($auth['id'])) . "." . $last_ext;        
                        move_uploaded_file($_FILES['image']['tmp_name'],$thumbnail);
                        
                            $succ[] = array("successful"	=>	"Your new photos was successfully uploaded.",
                                            "img"		=>	"/"  . $thumbnail,
					    "userType"		=>	$profilePic);
			
                            echo json_encode($succ);
                    }
            }
}


?>